 /**
 * 菜单栏目
 */
(function($){
	$.purviewmenu = function(opts) {
		this.opts = opts;
	};
	$.extend($.purviewmenu.prototype,{
		createMenu:function(){
			var options = this.opts;
			var basePath = options.basePath;
			var containers = "";
			$.getJSON(basePath+"/PurviewMenu?mark="+options.mark,function(result){
				if(result != null){
					$.each(result,function(key,item){
						containers += "<h3 id=\"menu"+key+"\" onclick=\"javascript:openMenu('"+item.menuKey+"');\">"+item.menuName+"</h3>";
						containers += "<ul id=\""+item.menuKey+"\">";
						$.each(item.childMenuList,function(i,child){
							containers += "<li id=\""+child.menuKey+"\" onclick=\"javascript:changeMenu('"+item.menuKey+"','"+child.menuKey+"','"+basePath+""+child.menuUrl+"','"+item.menuName+"-->"+child.menuName+"');\">"+child.menuName+"</li>";
						});
						containers += "</ul>";
					});
				}
			});
			return containers;
		}
	});
	window.openMenu = function(index) {
		$("ul").each(function(key){
			if(this.id == index){
				$("#menu"+key+"").addClass("on");
				$("#"+index+"").show(500);
			}else{
				$("#menu"+key+"").removeClass("on");
				$("#"+this.id+"").hide();
			}
		});
	};
	window.changeMenu = function(index,child,url,caption){
		$("ul#"+index+">li").removeClass("on");
		$("ul#"+index+">#"+child+"").addClass("on");
		var mainFrame = top.$("#mainFrame");
		mainFrame.contents().empty();
		mainFrame.removeAttr("src");
		mainFrame.attr("src", url);
		$("#poit").text(caption);
	};
	$.fn.loadMenu = function(opts){
		var evt = new $.purviewmenu(opts);
		var menu = evt.createMenu();
		this.empty();
		$(menu).appendTo(this);
	};
})(jQuery);